<?php

/**
 * principal actions.
 *
 * @package    damicoweb
 * @subpackage principal
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class principalActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  * TODO: crear el noticiaPager y el eventoPager en métodos para reutilizar
  */
  public function executeIndex(sfWebRequest $request)
  {
  	//paginador de noticias
	$this->noticiaPager = new sfDoctrinePager('Noticia', sfConfig::get('app_max_noticias_en_principal', 3));
	$this->noticiaPager->setQuery(NoticiaTable::getInstance()->addNoticiasPorFechaQuery(null, false));
	$this->noticiaPager->setPage($request->getParameter('noticiaPage', 1));
	$this->noticiaPager->init();

	//paginador de eventos
    $this->eventoPager = new sfDoctrinePager('Evento', sfConfig::get('app_max_eventos_en_principal', 3));
	$this->eventoPager->setQuery(EventoTable::getInstance()->addEventosPorFechaQuery());
	$this->eventoPager->setPage($request->getParameter('eventoPage', 1));
	$this->eventoPager->init();
  }
  
  public function executeCambiarPaginaNoticia(sfWebRequest $request){
	//paginador de noticias
	$this->noticiaPager = new sfDoctrinePager('Noticia', sfConfig::get('app_max_noticias_en_principal', 3));
	$this->noticiaPager->setQuery(NoticiaTable::getInstance()->addNoticiasPorFechaQuery(null, false));
	$this->noticiaPager->setPage($request->getParameter('noticiaPage', 1));
	$this->noticiaPager->init();
	return $this->renderPartial('principal/noticias');
  }

  public function executeCambiarPaginaEvento(sfWebRequest $request){
	//paginador de eventos
    $this->eventoPager = new sfDoctrinePager('Evento', sfConfig::get('app_max_eventos_en_principal', 3));
	$this->eventoPager->setQuery(EventoTable::getInstance()->addEventosPorFechaQuery());
	$this->eventoPager->setPage($request->getParameter('eventoPage', 1));
	$this->eventoPager->init();
	return $this->renderPartial('principal/eventos');
  }
  
  public function executeNoticiaView(sfWebRequest $request)
  {
  	$id = $request->getParameter('id');
  	$this->noticia = NoticiaTable::getInstance()->getNoticia($id);
  	
  	$this->anterior = NoticiaTable::getInstance()->getNoticiaAnterior($id);
  	$this->posterior = NoticiaTable::getInstance()->getNoticiaPosterior($id);
  }
  
  public function executeEventoView(sfWebRequest $request)
  {
  	$id = $request->getParameter('id');
  	$this->evento = EventoTable::getInstance()->getEvento($id);
  	
  	$this->anterior = EventoTable::getInstance()->getEventoAnterior($id);
  	$this->posterior = EventoTable::getInstance()->getEventoPosterior($id);
  }
}